﻿namespace com.crownpack.SharePoint
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;

    public class CustomLoggingService : SPDiagnosticsServiceBase
    {
        #region Fields

        const string defaultname = "Custom Logging";

        static CustomLoggingService _Local;
        static string _name;
        static object _objectlock;

        #endregion Fields

        #region Constructors

        public CustomLoggingService( )
            : base(name, SPFarm.Local)
        {
        }

        #endregion Constructors

        #region Enumerations

        public enum Area
        {
            FeatureInfrastructure,
            Fields,
            General,
            TimerJob,
            WebControls,
            WebParts,
            WorkflowInfrastructure
        }

        #endregion Enumerations

        #region Properties

        public static CustomLoggingService Local
        {
            get
            {
                lock ( objectlock )
                {
                    if ( _Local == null )
                        _Local = SPFarm.Local.Services.GetValue<CustomLoggingService>( name );
                    if ( _Local == null )
                        _Local = new CustomLoggingService( );
                    return _Local;
                }
            }
        }

        static string name
        {
            get
            {
                if ( string.IsNullOrEmpty( _name ) )
                    _name = defaultname;
                return _name;
            }
            set
            {
                if ( string.IsNullOrEmpty( _name ) || !_name.Equals( value, StringComparison.OrdinalIgnoreCase ) )
                {
                    _name = value;
                    _Local = null;
                }
            }
        }

        static object objectlock
        {
            get
            {
                if ( _objectlock == null )
                    _objectlock = new object( );
                return _objectlock;
            }
        }

        #endregion Properties

        #region Methods

        public static void LogCritical( string source, Area area, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, message );
        }

        public static void LogCritical( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCritical( string source, Area area, short id, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Critical, message );
        }

        public static void LogCritical( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCritical( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCritical( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCritical( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCritical( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCritical( Area area, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, message );
        }

        public static void LogCritical( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCritical( Area area, short id, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Critical, message );
        }

        public static void LogCritical( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCritical( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCritical( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCritical( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCritical( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToEventLog( Area area, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, message );
        }

        public static void LogCriticalToEventLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToEventLog( Area area, short id, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Critical, message );
        }

        public static void LogCriticalToEventLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToEventLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToEventLog( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToEventLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToEventLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToEventLog( string source, Area area, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, message );
        }

        public static void LogCriticalToEventLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToEventLog( string source, Area area, short id, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Critical, message );
        }

        public static void LogCriticalToEventLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToEventLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToEventLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToEventLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToEventLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToTraceLog( string source, Area area, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, message );
        }

        public static void LogCriticalToTraceLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToTraceLog( string source, Area area, short id, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Critical, message );
        }

        public static void LogCriticalToTraceLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToTraceLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToTraceLog( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToTraceLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToTraceLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToTraceLog( Area area, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, message );
        }

        public static void LogCriticalToTraceLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToTraceLog( Area area, short id, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Critical, message );
        }

        public static void LogCriticalToTraceLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Critical, string.Format( message, args ) );
        }

        public static void LogCriticalToTraceLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToTraceLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogCriticalToTraceLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Critical, flattenException( exception, message ) );
        }

        public static void LogCriticalToTraceLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Critical, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogError( Area area, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Error, message );
        }

        public static void LogError( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Error, string.Format( message, args ) );
        }

        public static void LogError( Area area, short id, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Error, message );
        }

        public static void LogError( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Error, string.Format( message, args ) );
        }

        public static void LogError( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Error, flattenException( exception, message ) );
        }

        public static void LogError( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogError( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Error, flattenException( exception, message ) );
        }

        public static void LogError( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogError( string source, Area area, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Error, message );
        }

        public static void LogError( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Error, string.Format( message, args ) );
        }

        public static void LogError( string source, Area area, short id, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Error, message );
        }

        public static void LogError( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Error, string.Format( message, args ) );
        }

        public static void LogError( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Error, flattenException( exception, message ) );
        }

        public static void LogError( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogError( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Error, flattenException( exception, message ) );
        }

        public static void LogError( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToEventLog( Area area, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Error, message );
        }

        public static void LogErrorToEventLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToEventLog( Area area, short id, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Error, message );
        }

        public static void LogErrorToEventLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToEventLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToEventLog( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToEventLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToEventLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToEventLog( string source, Area area, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Error, message );
        }

        public static void LogErrorToEventLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToEventLog( string source, Area area, short id, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Error, message );
        }

        public static void LogErrorToEventLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToEventLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToEventLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToEventLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToEventLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToTraceLog( string source, Area area, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Error, message );
        }

        public static void LogErrorToTraceLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToTraceLog( string source, Area area, short id, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Error, message );
        }

        public static void LogErrorToTraceLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToTraceLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToTraceLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToTraceLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToTraceLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToTraceLog( Area area, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Error, message );
        }

        public static void LogErrorToTraceLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToTraceLog( Area area, short id, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Error, message );
        }

        public static void LogErrorToTraceLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Error, string.Format( message, args ) );
        }

        public static void LogErrorToTraceLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToTraceLog( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogErrorToTraceLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Error, flattenException( exception, message ) );
        }

        public static void LogErrorToTraceLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Error, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogMessage( string source, Area area, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Information, message );
        }

        public static void LogMessage( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessage( Area area, short id, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Information, message );
        }

        public static void LogMessage( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessage( Area area, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Information, message );
        }

        public static void LogMessage( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessage( string source, Area area, short id, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Information, message );
        }

        public static void LogMessage( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToEventLog( Area area, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Information, message );
        }

        public static void LogMessageToEventLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToEventLog( string source, Area area, short id, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Information, message );
        }

        public static void LogMessageToEventLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToEventLog( string source, Area area, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Information, message );
        }

        public static void LogMessageToEventLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToEventLog( Area area, short id, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Information, message );
        }

        public static void LogMessageToEventLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToTraceLog( string source, Area area, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Information, message );
        }

        public static void LogMessageToTraceLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToTraceLog( string source, Area area, short id, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Information, message );
        }

        public static void LogMessageToTraceLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToTraceLog( Area area, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Information, message );
        }

        public static void LogMessageToTraceLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Information, string.Format( message, args ) );
        }

        public static void LogMessageToTraceLog( Area area, short id, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Information, message );
        }

        public static void LogMessageToTraceLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Information, string.Format( message, args ) );
        }

        public static void LogVerbose( string source, Area area, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, message );
        }

        public static void LogVerbose( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerbose( string source, Area area, short id, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Verbose, message );
        }

        public static void LogVerbose( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerbose( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerbose( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerbose( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerbose( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerbose( Area area, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, message );
        }

        public static void LogVerbose( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerbose( Area area, short id, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Verbose, message );
        }

        public static void LogVerbose( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerbose( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerbose( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerbose( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerbose( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToEventLog( string source, Area area, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, message );
        }

        public static void LogVerboseToEventLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToEventLog( string source, Area area, short id, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Verbose, message );
        }

        public static void LogVerboseToEventLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToEventLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToEventLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToEventLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToEventLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToEventLog( Area area, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, message );
        }

        public static void LogVerboseToEventLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToEventLog( Area area, short id, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Verbose, message );
        }

        public static void LogVerboseToEventLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToEventLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToEventLog( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToEventLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToEventLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToTraceLog( string source, Area area, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, message );
        }

        public static void LogVerboseToTraceLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToTraceLog( string source, Area area, short id, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Verbose, message );
        }

        public static void LogVerboseToTraceLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToTraceLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToTraceLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToTraceLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToTraceLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToTraceLog( Area area, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, message );
        }

        public static void LogVerboseToTraceLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToTraceLog( Area area, short id, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Verbose, message );
        }

        public static void LogVerboseToTraceLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Verbose, string.Format( message, args ) );
        }

        public static void LogVerboseToTraceLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToTraceLog( Area area, Exception exception, string message, params object[ ] args )
        {
            writeTrace( getCategory( area ), getId( ), Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogVerboseToTraceLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Verbose, flattenException( exception, message ) );
        }

        public static void LogVerboseToTraceLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Verbose, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarning( string source, Area area, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, message );
        }

        public static void LogWarning( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarning( string source, Area area, short id, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Warning, message );
        }

        public static void LogWarning( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarning( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarning( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarning( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarning( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeBoth( getCategory( area ), id, Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarning( Area area, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, message );
        }

        public static void LogWarning( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarning( Area area, short id, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Warning, message );
        }

        public static void LogWarning( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarning( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarning( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarning( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarning( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeBoth( getCategory( area ), id, Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToEventLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToEventLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToEventLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToEventLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToEventLog( string source, Area area, string message )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, message );
        }

        public static void LogWarningToEventLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarningToEventLog( string source, Area area, short id, string message )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Warning, message );
        }

        public static void LogWarningToEventLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeEvent( getCategory( area ), id, Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarningToEventLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToEventLog( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToEventLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToEventLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToEventLog( Area area, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, message );
        }

        public static void LogWarningToEventLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), getId( ), Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarningToEventLog( Area area, short id, string message )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Warning, message );
        }

        public static void LogWarningToEventLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeEvent( getCategory( area ), id, Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarningToTraceLog( string source, Area area, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToTraceLog( string source, Area area, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToTraceLog( string source, Area area, short id, Exception exception, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToTraceLog( string source, Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToTraceLog( string source, Area area, string message )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, message );
        }

        public static void LogWarningToTraceLog( string source, Area area, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarningToTraceLog( string source, Area area, short id, string message )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Warning, message );
        }

        public static void LogWarningToTraceLog( string source, Area area, short id, string message, params object[ ] args )
        {
            name = source;
            writeTrace( getCategory( area ), id, Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarningToTraceLog( Area area, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToTraceLog( Area area, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToTraceLog( Area area, short id, Exception exception, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Warning, flattenException( exception, message ) );
        }

        public static void LogWarningToTraceLog( Area area, short id, Exception exception, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Warning, flattenException( exception, string.Format( message, args ) ) );
        }

        public static void LogWarningToTraceLog( Area area, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, message );
        }

        public static void LogWarningToTraceLog( Area area, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), getId( ), Severity.Warning, string.Format( message, args ) );
        }

        public static void LogWarningToTraceLog( Area area, short id, string message )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Warning, message );
        }

        public static void LogWarningToTraceLog( Area area, short id, string message, params object[ ] args )
        {
            name = defaultname;
            writeTrace( getCategory( area ), id, Severity.Warning, string.Format( message, args ) );
        }

        protected override IEnumerable<SPDiagnosticsArea> ProvideAreas( )
        {
            List<SPDiagnosticsArea> diagnosticAreas = new List<SPDiagnosticsArea>( );
            List<SPDiagnosticsCategory> categories = new List<SPDiagnosticsCategory>( );
            foreach ( string t in categorynames.GetCategoryNames( ) )
            {
                categories.Add( new SPDiagnosticsCategory( t, t, Severity.GetTraceSeverity( Severity.Verbose ), Severity.GetEventSeverity( Severity.Verbose ), 0, 0, false, true ) );
            }
            diagnosticAreas.Add( new SPDiagnosticsArea( name, 0, 0, false, categories ) );
            return diagnosticAreas;
        }

        static string flattenException( Exception exception, string message )
        {
            string s = string.Empty;
            if ( !string.IsNullOrEmpty( message ) && exception != null )
                s = string.Format( "{0}\r\n{1}\r\n{2}\r\n{3}", message, exception.Message, exception.InnerException, exception.StackTrace );
            else if ( exception != null )
                s = string.Format( "{0}\r\n{1}\r\n{2}", exception.Message, exception.InnerException, exception.StackTrace );
            else
                s = message;
            return s;
        }

        static SPDiagnosticsCategory getCategory( Area area )
        {
            return Local.Areas[ name ].Categories[ xlatArea( area ) ];
        }

        static short getId( )
        {
            short j = 0;
            while ( j == 0 )
            {
                string i = DateTime.Now.ToString( "ssfff" );
                Int16.TryParse( i, out j );
            }
            return j;
        }

        static void writeBoth( SPDiagnosticsCategory category, short id, string severity, string message )
        {
            writeTrace( category, id, severity, message );
            writeEvent( category, id, severity, message );
        }

        static void writeEvent( SPDiagnosticsCategory category, short id, string severity, string message )
        {
            EventSeverity eventSeverity = Severity.GetEventSeverity( severity );
            CustomLoggingService service = Local;
            if ( service != null )
            {
                SPSecurity.RunWithElevatedPrivileges( delegate( )
                {
                    service.WriteEvent( ( ushort ) id, category, eventSeverity, message );
                } );
            }
            else
                throw new Exception( string.Format( "{0} not found.", name ) );
        }

        static void writeTrace( SPDiagnosticsCategory category, short id, string severity, string message )
        {
            TraceSeverity traceSeverity = Severity.GetTraceSeverity( severity );
            CustomLoggingService service = Local;
            if ( service != null )
            {
                SPSecurity.RunWithElevatedPrivileges( delegate( )
                {
                    service.WriteTrace( ( ushort ) id, category, traceSeverity, message );
                } );
            }
            else
                throw new Exception( string.Format( "{0} not found.", name ) );
        }

        static string xlatArea( Area area )
        {
            string a = string.Empty;
            switch ( area )
            {
                case Area.FeatureInfrastructure:
                    a = categorynames.FeatureInfrastructure;
                    break;
                case Area.Fields:
                    a = categorynames.Fields;
                    break;
                case Area.General:
                    a = categorynames.General;
                    break;
                case Area.TimerJob:
                    a = categorynames.TimerJob;
                    break;
                case Area.WebControls:
                    a = categorynames.WebControls;
                    break;
                case Area.WebParts:
                    a = categorynames.WebParts;
                    break;
                case Area.WorkflowInfrastructure:
                    a = categorynames.WorkflowInfrastructure;
                    break;
                default:
                    a = categorynames.General;
                    break;
            }
            return a;
        }

        #endregion Methods

        #region Nested Types

        public class EventLog
        {
            #region Fields

            public const string ApplicationRegistryKeyPath = @"SYSTEM\CurrentControlSet\services\eventlog\Application";
            public const string ApplicationRegistrySubkeyName = "CustomLogging";

            #endregion Fields
        }

        class categorynames
        {
            #region Fields

            internal const string FeatureInfrastructure = "Feature Infrastructure";
            internal const string Fields = "Fields";
            internal const string General = "General";
            internal const string TimerJob = "Timer Job";
            internal const string WebControls = "Web Controls";
            internal const string WebParts = "Web Parts";
            internal const string WorkflowInfrastructure = "Workflow Infrastructure";

            #endregion Fields

            #region Methods

            internal static List<string> GetCategoryNames( )
            {
                return new string[ ] { FeatureInfrastructure, Fields, General, TimerJob, WebControls, WebParts, WorkflowInfrastructure }.Distinct( ).ToList( );
            }

            #endregion Methods
        }

        class Severity
        {
            #region Fields

            internal const string Critical = "Critical";
            internal const string Error = "Error";
            internal const string Information = "Information";
            internal const string Verbose = "Verbose";
            internal const string Warning = "Warning";

            #endregion Fields

            #region Methods

            internal static EventSeverity GetEventSeverity( string severity )
            {
                if ( severity.Equals( Critical ) )
                    return EventSeverity.ErrorCritical;
                if ( severity.Equals( Error ) )
                    return EventSeverity.Error;
                if ( severity.Equals( Warning ) )
                    return EventSeverity.Warning;
                if ( severity.Equals( Information ) )
                    return EventSeverity.Information;
                return EventSeverity.Verbose;
            }

            internal static TraceSeverity GetTraceSeverity( string severity )
            {
                if ( severity.Equals( Critical ) )
                    return TraceSeverity.Unexpected;
                if ( severity.Equals( Error ) )
                    return TraceSeverity.Monitorable;
                if ( severity.Equals( Warning ) )
                    return TraceSeverity.High;
                if ( severity.Equals( Information ) )
                    return TraceSeverity.Medium;
                return TraceSeverity.Verbose;
            }

            #endregion Methods
        }

        #endregion Nested Types
    }
}